//var arrPrivi= new Array();	// Stores User Privileges
function checkPrivilege(strID){
		try{
			var blnReturn =false;
			if (strID != ""){
				if(top.arrPrivi[strID]=='1'){
					blnReturn = true;
				}else{
					 blnReturn = false;
				}		
			}else{
				blnReturn = true;
			}
		}catch(e){
			return false;
		}
		return blnReturn;
}

function enforcePrivileges() {
	
	$("[privilege]").each(function() {
		
		// Skip blanks
		if ($(this).attr("privilege")=="") return;
		
		// Check for privilege
		if (! checkPrivilege($(this).attr("privilege"))) {
			// If does not have the mentioned privilege, disable the control
			$(this).attr("disabled", true);
		}
	});
}

function enableElement(id, blnForce) {
		var elm = $("#" + id);

		if (blnForce) {
			// Forcefully enable. Do not check for disableAlways or privileges.
			elm.removeAttr("disabled");
			return;
		}

		// Check for privielges attribute
		if (elm.attr("privilege")!=undefined) {

			var strPrivis = elm.attr("privilege");

			// Seperate Privileges by space (' ')
			var arrPrivis = $.trim(strPrivis).split(" ");

			for (var i=0; i < arrPrivis.length; i++) {
				if (!checkPrivilege(arrPrivis[i])) {
					return false;
				}
			}
		}

		// Dont enable if it has disableAlways class
		if (elm.hasClass("disableAlways")) {
			// Do not enable
			return false;
		}

		elm.removeAttr("disabled");

		//enable if any datepickers/calendar attached.
		if(elm.hasClass("calendar")){
			elm.datepicker('enable');
		}

		return true;
	}
